<?php
class MHDEV_View_Helper_GetRootline extends Zend_View_Helper_Abstract
{
	public function GetRootline($board_uid, $thread_uid = FALSE, $user_uid = FALSE, $type = FALSE)
	{
		// init
		$content	= FALSE;
		$spacer		= '&nbsp;&raquo;&nbsp;';
		
		// helper
		$url		= new Zend_View_Helper_Url();
		
		// db
		$boards		= new Boards();
		$threads	= new Threads();
		
		if($user_uid)
		{
			$userName	= new MHDEV_View_Helper_GetAuthor();
			$content 	= $spacer.$userName->GetAuthor($user_uid); 
		}
		elseif ($type == 'edit' && $thread_uid)
		{
			$content	.= Zend_Registry::get('lang')->_('rootline_post_edit');
			$getThread	= $threads->find(intval($thread_uid));
			if($getThread->count() > 0) {
				$arrayThread = $getThread->toArray();
				$content	.= $spacer;		
				$content	.= '<a href="' . $url->url(array('controller' => 'posts', 'uid' => $thread_uid, 'title' => $arrayThread[0]['title']),'threads', true). '">';
				$content	.= $arrayThread[0]['title'];
				$content	.= '</a>';
			}
		}
		else
		{
			// query
			$getBoard	= $boards->find(intval($board_uid));
			
			// results
			if($getBoard->count() > 0 && !$thread_uid) {
				$arrayBoard = $getBoard->toArray();
				
				if($arrayBoard[0]['root_uid'] != 0)
				{
					$getRootBoard 	= $boards->find($arrayBoard[0]['root_uid']);
					$arrayRootBoard	= $getRootBoard->toArray();
					
					$content	.= $spacer;
					$content	.= '<a href="' . $url->url(array('controller' => 'threads', 'uid' => $arrayRootBoard[0]['uid'], 'title' => $arrayRootBoard[0]['title']),'boards', true). '">';
					$content	.= $arrayRootBoard[0]['title'];
					$content	.= '</a>';
					$content	.= $spacer;
					$content	.= $arrayBoard[0]['title'];
				}
				else
				{
					$content	.= $spacer;
					$content	.= $arrayBoard[0]['title'];
				}
			}
			elseif($getBoard->count() > 0 && $thread_uid)
			{
				$arrayBoard = $getBoard->toArray();
				$content	.= $spacer;
				$content	.= '<a href="' . $url->url(array('controller' => 'threads', 'uid' => $arrayBoard[0]['uid'], 'title' => $arrayBoard[0]['title']),'boards', true). '">';
				$content	.= $arrayBoard[0]['title'];
				$content	.= '</a>';
			}
			
			if($thread_uid)
			{
				$getThread = $threads->find(intval($thread_uid));
				if($getThread->count() > 0) {
					$arrayThread = $getThread->toArray();
					$content	.= $spacer;			
					$content	.= '<span id="topic_name">' . $arrayThread[0]['title'] . '</span>';
				}
			}
		}
		
		return $content;
	}
}